package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlTag;
import com.lemon.blog.system.service.IBlTagService;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import com.lemon.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlTagController
 * 类描述：标签管理Controller
 * 创建人：@author huangpeng
 * 创建时间：2022-05-04
 */
@Api("标签管理")
@RestController
@RequestMapping("/tag")
public class BlTagController extends BaseController
{
    @Autowired
    private IBlTagService blTagService;

    /**
     * 查询标签管理列表
     * @Title: list
     * @Description: 查询标签管理列表
     * @param blTag
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2023/4/30 22:04
     */
    @RequiresPermissions("blog:tag:list")
    @GetMapping("/list")
    public TableDataInfo list(BlTag blTag) {
        startPage();
        List<BlTag> list = blTagService.selectBlTagList(blTag);
        return getDataTable(list);
    }

    /**
     * 导出标签管理列表
     * @Title: export
     * @Description: 导出标签管理列表
     * @param response
     * @param blTag
     * @return: void
     * @throws:
     * @author: huangpeng
     * @Date: 2023/4/30 22:04
     */
    @RequiresPermissions("blog:tag:export")
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlTag blTag) {
        List<BlTag> list = blTagService.selectBlTagList(blTag);
        ExcelUtil<BlTag> util = new ExcelUtil<BlTag>(BlTag.class);
        util.exportExcel(response, list, "标签管理数据");
    }

    /**
     * 获取标签管理详细信息
     * @Title: getInfo
     * @Description: 获取标签管理详细信息
     * @param tagId
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/4/30 22:04
     */
    @RequiresPermissions("blog:tag:query")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId) {
        return AjaxResult.success(blTagService.selectByPrimaryKey(tagId));
    }

    /**
     * 新增标签管理
     * @Title: add
     * @Description: 新增标签管理
     * @param blTag
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/4/30 22:04
     */
    @RequiresPermissions("blog:tag:add")
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlTag blTag) {
        return toAjax(blTagService.insert(blTag));
    }

    /**
     * 修改标签管理
     * @Title: edit
     * @Description: 修改标签管理
     * @param blTag
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/4/30 22:04
     */
    @RequiresPermissions("blog:tag:edit")
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlTag blTag) {
        return toAjax(blTagService.update(blTag));
    }

    /**
     * 删除标签管理
     * @Title: remove
     * @Description: 删除标签管理
     * @param tagIds
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 1:56
     */
    @RequiresPermissions("blog:tag:remove")
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
    @RequestMapping(value = "{tagIds}",method = RequestMethod.DELETE)
    public AjaxResult remove(@PathVariable Long[] tagIds) {
        return toAjax(blTagService.deleteByBatch(tagIds));
    }

    /**
     * 获取所有标签信息
     * @Title: queryAllTag
     * @Description: 获取所有标签信息
     * @param
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/4/30 0:32
     */
    @GetMapping("/queryAll")
    public AjaxResult queryAllTag() {
        return AjaxResult.success(blTagService.queryAllTag());
    }

    /**
     * 根据标签名获取标签
     * @Title: getInfo
     * @Description: 根据标签名获取标签
     * @param tagName
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/4/30 0:32
     */
    @RequiresPermissions("blog:tag:query")
    @GetMapping(value = "/queryByTagName/{tagName}")
    public AjaxResult getInfo(@PathVariable("tagName") String tagName) {
        return AjaxResult.success(blTagService.selectBlTagByTagName(tagName));
    }
}
